// VERSION: 1.8 LAST UPDATE: 9.03.2011
/* 
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 * 
 * Made by Wilq32, wilq32@gmail.com, Wroclaw, Poland, 01.2009
 * Website: http://code.google.com/p/jqueryrotate/ 
 */

// Documentation removed from script file (was kinda useless and outdated)

(function($) {
var supportedCSS,styles=document.getElementsByTagName("head")[0].style,toCheck="transformProperty WebkitTransform OTransform msTransform MozTransform".split(" ");
for (var a=0;a<toCheck.length;a++) if (styles[toCheck[a]] !== undefined) supportedCSS = toCheck[a];
// Bad eval to preven google closure to remove it from code o_O
// After compresion replace it back to var IE = 'v' == '\v'
var IE = eval('"v"=="\v"');

jQuery.fn.extend({
ImageRotate:function(parameters)
{
	// If this element is already a Wilq32.PhotoEffect object, skip creation
	if (this.Wilq32&&this.Wilq32.PhotoEffect) return;
	// parameters might be applied to many objects - so because we use them later - a fresh instance is needed 
	var paramClone = $.extend(true, {}, parameters); 
	return (new Wilq32.PhotoEffect(this.get(0),paramClone))._rootObj;
},
rotate:function(parameters)
{
	if (this.length===0||typeof parameters=="undefined") return;
	if (typeof parameters=="number") parameters={angle:parameters};
	var returned=[];
	for (var i=0,i0=this.length;i<i0;i++)
	{
	    var element=this.get(i);	
		if (typeof element.Wilq32 == "undefined") 
			returned.push($($(element).ImageRotate(parameters)));
		else 
            element.Wilq32.PhotoEffect._handleRotation(parameters);
	}
	return returned;
}
});

// Library agnostic interface

Wilq32=window.Wilq32||{};
Wilq32.PhotoEffect=(function(){

	if (supportedCSS) {
		return function(img,parameters){
			img.Wilq32 = {
				PhotoEffect: this
			};
            
            this._img = this._rootObj = this._eventObj = img;
            this._handleRotation(parameters);
		}
	} else {
		return function(img,parameters) {
			// Make sure that class and id are also copied - just in case you would like to refeer to an newly created object
            this._img = img;

			this._rootObj=document.createElement('span');
			this._rootObj.style.display="inline-block";
			this._rootObj.Wilq32 = 
				{
					PhotoEffect: this
				};
			img.parentNode.insertBefore(this._rootObj,img);
			
			if (img.complete) {
				this._Loader(parameters);
			} else {
				var self=this;
				// TODO: Remove jQuery dependency
				jQuery(this._img).bind("load", function()
				{
					self._Loader(parameters);
				});
			}
		}
	}
})();

Wilq32.PhotoEffect.prototype={
    _setupParameters : function (parameters){
		this._parameters = this._parameters || {};
        if (typeof this._angle !== "number") this._angle = 0 ;
        if (typeof parameters.angle==="number") this._angle = parameters.angle;
        this._parameters.animateTo = (typeof parameters.animateTo==="number") ? (parameters.animateTo) : (this._angle); 

		this._parameters.easing = parameters.easing || this._parameters.easing || function (x, t, b, c, d) { return -c * ((t=t/d-1)*t*t*t - 1) + b; }
		this._parameters.duration = parameters.duration || this._parameters.duration || 1000;
        this._parameters.callback = parameters.callback || this._parameters.callback || function(){};
        if (parameters.bind && parameters.bind != this._parameters.bind) this._BindEvents(parameters.bind); 
	},
	_handleRotation : function(parameters){
          this._setupParameters(parameters);
          if (this._angle==this._parameters.animateTo) {
              this._rotate(this._angle);
          }
          else { 
              this._animateStart();          
          }
	},

	_BindEvents:function(events){
		if (events && this._eventObj) 
		{
            // Unbinding previous Events
            if (this._parameters.bind){
                var oldEvents = this._parameters.bind;
                for (var a in oldEvents) if (oldEvents.hasOwnProperty(a)) 
                        // TODO: Remove jQuery dependency
                        jQuery(this._eventObj).unbind(a,oldEvents[a]);
            }

            this._parameters.bind = events;
			for (var a in events) if (events.hasOwnProperty(a)) 
				// TODO: Remove jQuery dependency
					jQuery(this._eventObj).bind(a,events[a]);
		}
	},

	_Loader:(function()
	{
		if (IE)
		return function(parameters)
		{
			var width=this._img.width;
			var height=this._img.height;
			this._img.parentNode.removeChild(this._img);
							
			this._vimage = this.createVMLNode('image');
			this._vimage.src=this._img.src;
			this._vimage.style.height=height+"px";
			this._vimage.style.width=width+"px";
			this._vimage.style.position="absolute"; // FIXES IE PROBLEM - its only rendered if its on absolute position!
			this._vimage.style.top = "0px";
			this._vimage.style.left = "0px";

			/* Group minifying a small 1px precision problem when rotating object */
			this._container =  this.createVMLNode('group');
			this._container.style.width=width;
			this._container.style.height=height;
			this._container.style.position="absolute";
			this._container.setAttribute('coordsize',width-1+','+(height-1)); // This -1, -1 trying to fix ugly problem with small displacement on IE
			this._container.appendChild(this._vimage);
			
			this._rootObj.appendChild(this._container);
			this._rootObj.style.position="relative"; // FIXES IE PROBLEM
			this._rootObj.style.width=width+"px";
			this._rootObj.style.height=height+"px";
			this._rootObj.setAttribute('id',this._img.getAttribute('id'));
			this._rootObj.className=this._img.className;			
		    this._eventObj = this._rootObj;	
		    this._handleRotation(parameters);	
		}
		else
		return function (parameters)
		{
			this._rootObj.setAttribute('id',this._img.getAttribute('id'));
			this._rootObj.className=this._img.className;
			
			this._width=this._img.width;
			this._height=this._img.height;
			this._widthHalf=this._width/2; // used for optimisation
			this._heightHalf=this._height/2;// used for optimisation
			
			var _widthMax=Math.sqrt((this._height)*(this._height) + (this._width) * (this._width));

			this._widthAdd = _widthMax - this._width;
			this._heightAdd = _widthMax - this._height;	// widthMax because maxWidth=maxHeight
			this._widthAddHalf=this._widthAdd/2; // used for optimisation
			this._heightAddHalf=this._heightAdd/2;// used for optimisation
			
			this._img.parentNode.removeChild(this._img);	
			
			this._aspectW = ((parseInt(this._img.style.width,10)) || this._width)/this._img.width;
			this._aspectH = ((parseInt(this._img.style.height,10)) || this._height)/this._img.height;
			
			this._canvas=document.createElement('canvas');
			this._canvas.setAttribute('width',this._width);
			this._canvas.style.position="relative";
			this._canvas.style.left = -this._widthAddHalf + "px";
			this._canvas.style.top = -this._heightAddHalf + "px";
			this._canvas.Wilq32 = this._rootObj.Wilq32;
			
			this._rootObj.appendChild(this._canvas);
			this._rootObj.style.width=this._width+"px";
			this._rootObj.style.height=this._height+"px";
            this._eventObj = this._canvas;
			
			this._cnv=this._canvas.getContext('2d');
            this._handleRotation(parameters);
		}
	})(),

	_animateStart:function()
	{	
		if (this._timer) {
			clearTimeout(this._timer);
		}
		this._animateStartTime = +new Date;
		this._animateStartAngle = this._angle;
		this._animate();
	},
_animate:function()
     {
         var actualTime = +new Date;
         var checkEnd = actualTime - this._animateStartTime > this._parameters.duration;

         // TODO: Bug for animatedGif for static rotation ? (to test)
         if (checkEnd && !this._parameters.animatedGif) 
         {
             clearTimeout(this._timer);
         }
         else 
         {
             if (this._canvas||this._vimage||this._img) {
                 var angle = this._parameters.easing(0, actualTime - this._animateStartTime, this._animateStartAngle, this._parameters.animateTo - this._animateStartAngle, this._parameters.duration);
                 this._rotate((~~(angle*10))/10);
             }
             var self = this;
             this._timer = setTimeout(function()
                     {
                     self._animate.call(self);
                     }, 10);
         }

         // To fix Bug that prevents using recursive function in callback I moved this function to back
         if (this._parameters.callback && checkEnd){
             this._angle = this._parameters.animateTo;
             this._rotate(this._angle);
             this._parameters.callback.call(this._rootObj);
         }
     },

	_rotate : (function()
	{
		var rad = Math.PI/180;
		if (IE)
		return function(angle)
		{
            this._angle = angle;
			this._container.style.rotation=(angle%360)+"deg";
		}
		else if (supportedCSS)
		return function(angle){
            this._angle = angle;
			this._img.style[supportedCSS]="rotate("+(angle%360)+"deg)";
		}
		else 
		return function(angle)
		{
            this._angle = angle;
			angle=(angle%360)* rad;
			// clear canvas	
			this._canvas.width = this._width+this._widthAdd;
			this._canvas.height = this._height+this._heightAdd;
						
			// REMEMBER: all drawings are read from backwards.. so first function is translate, then rotate, then translate, translate..
			this._cnv.translate(this._widthAddHalf,this._heightAddHalf);	// at least center image on screen
			this._cnv.translate(this._widthHalf,this._heightHalf);			// we move image back to its orginal 
			this._cnv.rotate(angle);										// rotate image
			this._cnv.translate(-this._widthHalf,-this._heightHalf);		// move image to its center, so we can rotate around its center
			this._cnv.scale(this._aspectW,this._aspectH); // SCALE - if needed ;)
			this._cnv.drawImage(this._img, 0, 0);							// First - we draw image
		}

	})()
}

if (IE)
{
Wilq32.PhotoEffect.prototype.createVMLNode=(function(){
document.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
		try {
			!document.namespaces.rvml && document.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
			return function (tagName) {
				return document.createElement('<rvml:' + tagName + ' class="rvml">');
			};
		} catch (e) {
			return function (tagName) {
				return document.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
			};
		}		
})();
}

})(jQuery);

/*
	My Script
*/

$(document).ready(function() {
	
	var c = 0;
	var $top = $('#top');
	var $banner = $('#header .headerBanner');
	var ie7 = false;
	
	if (($.browser.msie  && parseInt($.browser.version, 10) === 7) || ($.browser.msie  && parseInt($.browser.version, 10) === 8)) {
		ie7 = true;
	}
	
	//le logo "grandit" au survol
	$top.find('.logo').hover(function() {
		$(this).animate({
			top: 0
		},'fast');
	}, function() {
		$(this).animate({
			top: -30
		},'fast');
	});
	
	//la bousole tourne en boucle
	var rotation = function (angleRandom) {
		var originAngle = angleRandom;
		var newAngle = Math.floor(Math.random()*360);
		
		$top.find('.logo .aiguille').rotate({
			angle:angleRandom, 
			animateTo:newAngle, 
			callback: rotation,
			easing: $.easing.easeInOutExpo
		});
	};
	var angleRandom = Math.floor(Math.random()*360);
	rotation(angleRandom);
	
	
	
	
	//affiche la liste des jeux
	$top.find('.blogTitle li.games').hover(function() {
		$(this).children('ul').stop(true,true).slideDown('fast');
	}, function() {
		$(this).children('ul').stop(true,true).slideUp('fast');
	});
	
	
	
	
	//anime la bannière
	var bannerSlide = function() {
		
		if ( ($banner.find('.current').index()+1) == $banner.find('img').length ) {
			
			$banner.find('.current').css('z-index','1');
			$banner.find('img:first').css('z-index','2').fadeIn(1000, function(){
				$banner.find('.current').hide().removeClass('current');
				$banner.find('img:first').addClass('current');
			});
		
		} else {
	
			$banner.find('.current').next().css('z-index','2').fadeIn(1000, function(){
				$banner.find('.current')
					.hide()
					.css('z-index','1')
					.removeClass('current')
					.next()
					.addClass('current');
			});
		}
	}
	if ( $banner.find('img').length > 1 ) {
		$banner.find('img:first').addClass('current').fadeIn();
		var t = setInterval(bannerSlide,3000);
	}
	
	
	//roster tab switcher
	$('.rosterNav a').on('click',function(e){
		e.preventDefault();
		if ( !$(this).hasClass('active') ) {
			var tabId = $(this).attr('class');
			$('.rosterNav a').removeClass('active');
			$(this).addClass('active');
			$('.rosterContent').slideUp();
			$('.rosterContent#'+tabId).slideDown();
		}
	});
	
	//dispoNav
	$('.dispoSelector li a').on('click',function(e){
		e.preventDefault();
		if ( !$(this).hasClass('active') ) {
			var tabId = $(this).attr('class');
			$('.dispoSelector a').removeClass('active');
			$(this).addClass('active');
			$('.dispoContainer .dispos_liste_classe').slideUp();
			$('.dispoContainer .dispos_liste_classe#'+tabId).slideDown();
		}
	});
	
	$('.dispoSelector.sub_page_title a').on('click',function() {
		$('.dispoContainer .dispos_liste_classe').slideDown();
	});
	
	//add class for styles
	$('.barres_laterales_gauche_titre, .barres_laterales_droite_titre').each(function() {
	
		if ( $(this).text() === 'Guild Ranking' ) {
			$(this).parent().addClass('guildRanking');
		}
		
		if ( $(this).text() === 'Recrutement' ) {
			$(this).parent().addClass('recrutement');
		}
	});
	
	if (!ie7) {
		$('#content .newsContent').after($('#content .barres_laterales_droite'));
	}
	$('#content .newsContent').before($('#content .barres_laterales_gauche'));
	
	
	$('#content .barres_laterales_gauche_titre, .barres_laterales_droite_titre').each(function(){
		var titleText = $(this).text();
		if ( titleText.search("Avancée") != -1 ) {
			$(this).parent().addClass('pve-progress');
		}
	});
	
	$('#content .progressContainer .progress').each(function(){
		var progressWidth = $(this).attr('data-width');
			progressWidth = progressWidth+'%';
		
		$(this)
		.css('width','0')
		.delay(c*100)
		.animate({
			width: progressWidth
		},600, function() {
			if ( progressWidth === "100%" ) {
				$(this).addClass('complete');
			}
		});
		c++;
	});

	
	$('.calendrier_raids_compo_place').each(function() {
		var pElement = $('.calendrier_raids_player_plate',this);
		if (pElement.is(':not(:first-child)')) {
			pElement.next().css('margin-right',0);
		}
	});
	
	$('.calendrier_raids_container').each(function() {
		$('.calendrier_raids_raid',this).css({
			height: $('.calendrier_raids_compo',this).height()
		});
	});
	
	$('.calendrier_raids_player_plate').each(function() {
		var backgroundClassColor = $(this).css('background-color');
		
		switch (backgroundClassColor) {
			case "rgb(255, 255, 255)" :
				$('td',this).addClass('lisible');
				$(this).css({ backgroundColor: "#eee" });
			break;
			case "rgb(255, 245, 105)" : $('td',this).addClass('lisible');
			break;
			default: $('td',this).removeClass('lisible');
		}
	});
	
});

